<?php
/**
 * 过滤只能是字母和数字
 * @param  [type]
 * @return [type]
 */
function checkLogin() {

	if (!isset($_SESSION['is_login']) && $_SESSION['is_login'] == 0) {

		header("Location:/" . APP_ADMIN_URI . "/login");
	}
}

/**
 * @param $total          总条数
 * @param $curpage          当前页
 * @param $num               每页条数
 * @param string $args
 * @param string $url
 * @return null|string
 */

function get_table_page_navigation($total, $curpage, $num, $args = "", $url = "") {
	if ($args != '') {
		$args = "&" . $args;
	}

	$args .= "&num=$num";
	$url .= false !== strpos($url, "?") ? "&" : "?";

	$total_page = ceil($total / $num);

	if ($total_page == 0) {
		$total_page = 1;
		$curpage = 1;
	}

	if ($total_page == 1) {
		return "";
	}
	$output = null;

	$output .= " <ul class=\"spage pagination no-margin\">";

	if ($curpage > 1) {
		$output .= '<li><a href=' . $url . 'page=1' . $args . ' title="首页">首页</a></li>';
		$output .= '<li><a href=' . $url . 'page=' . ($curpage - 1) . $args . ' title="上一页">上一页</a></li>';
	} else {
		$output .= '<li class="disabled"><a href=' . $url . 'page=1' . $args . ' title="首页">首页</a></li>';
		$output .= '<li class="disabled"><a href=' . $url . 'page=' . ($curpage - 1) . $args . ' title="上一页">上一页</a></li>';
	}

	$start = floor($curpage / 10) * 10;
	$end = $start + 9;
	if ($start < 1) {
		$start = 1;
	}

	if ($end > $total_page) {
		$end = $total_page;
	}

	$output .= " ";
	for ($i = $start; $i <= $end; $i++) {
		$output .= ($i != 1 && $i % 10) ? " " : "";

		if ($curpage == $i) {
			$output .= '<li class="active"><a href="#" onclick="return false;" class="this-page">' . $i . '</a></li>'; //输出当前页数
		} else {
			$output .= '<li><a href="' . $url . 'page=' . ($i) . $args . '">' . $i . '</a></li>'; //输出页数
		}
	}

	if ($curpage < $total_page) {
		$output .= '<li><a href="' . $url . 'page=' . ($curpage + 1) . $args . '" title="下一页">下一页</a></li>';
	} else {
		$output .= '<li class="disabled"><a href=' . $url . 'page=' . ($total_page) . $args . ' title="末页">末页</a></li>';
	}

	return $output;
}